<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div style="padding: 20px 40px;">
        <button id="btn">点击开始</button>
        <button id="stop">点击停止</button>

        <div id="content" style="margin-top: 40px;">

        </div>
    </div>
    <script>
        const sourceWrapper = { value: undefined };
        const startListening = () => {
            sourceWrapper.value = new EventSource('http://localhost:3000/sse');
            sourceWrapper.value.onmessage = e => {
                console.log(e); 
                document.getElementById('content').innerText += e.data;
            }
        }
        const stopListening = () => {
            sourceWrapper.value.close();
        }
        document.getElementById('btn').onclick = startListening;
        document.getElementById('stop').onclick = stopListening;
    </script>
</body>
</html>